from multiprocessing import Process
from queue import Queue
import requests

# 创建一个队列，添加10个任务


q = Queue()

a = 1

for i in range(10):
    q.put("http://www.baidu.com")

def work1():
    global a
    while True:
        # 判断队列是否有任务
        if q.qsize()>0:
            url = q.get()
            requests.get(url)
            print(f"work1正在执行任务---第{a}次")
            a += 1

def work2():
    global a
    while True:
        if q.qsize()>0:
            url = q.get()
            requests.get(url)
            print(f"work2正在执行任务---第{a}次")
            a += 1

if __name__ == '__main__':
    p1 = Process(target=work1)
    p2 = Process(target=work2)
    p1.start()
    p2.start()
